var twoSum = function(nums, target) {
    var result = [], left = right = middle = temp = 0;
    if(target<nums[0]) return;
    for(let i=0;i<nums.length;i++){
        // 初始化
        temp = target-nums[i];
        left = i+1;
        right = nums.length;
        while(left<=right){
            middle = Math.floor((left+right)/2);
            if(nums[middle]>temp){
                right = middle-1;
            } else if(nums[middle]<temp){
                left = middle+1;
            } else{
                result.push(nums[i],nums[middle]);
                return result;
            }
        }
    }
    return;
};

var arr = [2,7,11,15], target = 9;
console.log(twoSum(arr,target));